/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package transervfx.Dato.Entidad;

import java.io.Serializable;
import java.util.List;
import javafx.beans.property.adapter.JavaBeanIntegerProperty;
import javafx.beans.property.adapter.JavaBeanIntegerPropertyBuilder;
import javafx.beans.property.adapter.JavaBeanStringProperty;
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;
import transervfx.Dato.Validacion.ValidacionesNivelLogico;

/**
 *
 * @author oscar
 */


@NamedQueries({
    @NamedQuery( name = "Gestor.findAll", query = "SELECT g FROM Gestor g"),
    @NamedQuery( name = "Gestor.findByTipoDocAndNroDoc", query = "SELECT g FROM Gestor g WHERE (g.nroDoc = :nroDoc) AND (g.tipoDoc = :tipoDoc)"),
    @NamedQuery( name = "Gestor.findByNombresAndApellido", query = "SELECT g FROM Gestor g WHERE (g.nombres = :nombres) AND (g.apellido = :apellido)")

})
@Entity
public class Gestor extends Persona implements Serializable {
    private static final long serialVersionUID = 1L;
   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @NotNull(message = "no puede ser nulo", groups = ValidacionesNivelLogico.class)
    @NotEmpty(message = "debe completarlo", groups = ValidacionesNivelLogico.class)
    @Size(min = 2, max = 30, message = "2 letras minimos, 30 maximo", groups = ValidacionesNivelLogico.class)
    private String nombres;
    
    @NotNull(message = "no puede ser nulo", groups = ValidacionesNivelLogico.class)
    @NotEmpty(message = "debe completarlo", groups = ValidacionesNivelLogico.class)
    @Size(min = 2, max = 30, message = "2 letras minimos, 30 maximo", groups = ValidacionesNivelLogico.class)
    private String apellido;
    
    @NotEmpty(message = "debe seleccionar uno", groups = ValidacionesNivelLogico.class)
    @Size(min = 2, max = 8, message = "seleccione uno", groups = ValidacionesNivelLogico.class)
    private String tipoDoc;
    
    @Range(min = 10000000, max = 99999999, message = "8 digitos como minimo y maximo", groups = ValidacionesNivelLogico.class)
    private Integer nroDoc;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy="gestor")
    private List<GuiaTramite> guiasTramites;
    
    
    //-------------------propiedades binding
    @Transient
    private JavaBeanStringProperty PROP_NOMBRES;
    
    @Transient
    private JavaBeanStringProperty PROP_APELLIDO;
    
    @Transient
    private JavaBeanIntegerProperty PROP_NRODOC;
    
    @Transient
    private JavaBeanStringProperty PROP_TIPODOC;
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNombres() {
        return nombres;
    }

    public void setNombres(String nombres) {
        this.nombres = nombres;
    }

    public String getApellido() {
        return apellido;
    }

    public void setApellido(String apellido) {
        this.apellido = apellido;
    }

    public String getTipoDoc() {
        return tipoDoc;
    }

    public void setTipoDoc(String tipoDoc) {
        this.tipoDoc = tipoDoc;
    }

    public Integer getNroDoc() {
        return nroDoc;
    }

    public void setNroDoc(Integer nroDoc) {
        this.nroDoc = nroDoc;
    }

    public List<GuiaTramite> getGuiasTramites() {
        return guiasTramites;
    }

    public void setGuiasTramites(List<GuiaTramite> guiasTramites) {
        this.guiasTramites = guiasTramites;
    }
    
  public JavaBeanStringProperty getPROP_NOMBRES() throws NoSuchMethodException {
        if (PROP_NOMBRES == null) {
            PROP_NOMBRES = JavaBeanStringPropertyBuilder.create().bean(this).name("nombres").build();
            getGroupBindProperties().add(PROP_NOMBRES);
        }
        return PROP_NOMBRES;
    }
    
    public JavaBeanStringProperty getPROP_APELLIDO() throws NoSuchMethodException {
        if (PROP_APELLIDO == null) {
            PROP_APELLIDO = JavaBeanStringPropertyBuilder.create().bean(this).name("apellido").build();
            getGroupBindProperties().add(PROP_APELLIDO);
        }
        return PROP_APELLIDO;
    }

    public JavaBeanIntegerProperty getPROP_NRODOC() throws NoSuchMethodException {

        if (PROP_NRODOC == null) {
            PROP_NRODOC = JavaBeanIntegerPropertyBuilder.create().bean(this).name("nroDoc").build();
            getGroupBindProperties().add(PROP_NRODOC);
        }
        return PROP_NRODOC;
    }

    public JavaBeanStringProperty getPROP_TIPODOC() throws NoSuchMethodException {

        if (PROP_TIPODOC == null) {
            PROP_TIPODOC = JavaBeanStringPropertyBuilder.create().bean(this).name("tipoDoc").build();
            getGroupBindProperties().add(PROP_TIPODOC);
        }
        return PROP_TIPODOC;
    }

    @Override
    public String toString() {
        return  nombres + " " + apellido ;
    }

    
    
    
}
